//Interrupt handler (Codename "Haber-Bosch")
#ifndef INTERRUPTHANDLER_H_
#define INTERRUPTHANDLER_H_
#include "scheduler.h"

//Adressen
#define AIC_BASE (0xFFFFF000) 
#define UI_BASE (0xFFFFFF00)
#define InterruptVectorAddress (volatile unsigned int*)(0x18)
#define SWIVectorAddress (volatile unsigned int*)(0x08)
#define SWIJumpAddress (volatile unsigned int*)(0x108)


//Remap offset
#define MC_RCR (volatile unsigned int*)(UI_BASE + 0x0000)
#define RCB	1<<0
  
//Interrupt enable pins (Standard edge triggered)
#define AIC_IECR (volatile unsigned int*)(AIC_BASE + 0x0120)	//Interrupt Enable Command Register
#define AIC_IDCR (volatile unsigned int*)(AIC_BASE + 0x0124)	//Interrupt Disable Command Register
#define AIC_IMR	 (volatile unsigned int*)(AIC_BASE + 0x0110)	//Interrupt Mask Register 
#define AIC_ISCR (volatile unsigned int*)(AIC_BASE + 0x012C)	//Interrupt Set Command Register
#define AIC_ICCR (volatile unsigned int*)(AIC_BASE + 0x0130)	//Interrupt Clear Command Register
#define AIC_IVR	(volatile unsigned int*)(AIC_BASE + 0x0100)	//Interrupt Vector Register  (Entry point of the interrupt handling)
#define AIC_IPR	(volatile unsigned int*)(AIC_BASE + 0x010C)	//Interrupt Pending Register
#define AIC_EOICR (volatile unsigned int*)(AIC_BASE + 0x0130)	//End of Interrupt Command Register
#define AIC_ISR (volatile unsigned int*)(AIC_BASE + 0x0108)	//Interrupt Status Register



//Interrupt Vector Table
#define AIC_SVR1 (volatile unsigned int*) (AIC_BASE + 0x0084)	//Interrupt Source Vector Register 1 (1-31)
#define AIC_SVR31 (volatile unsigned int*) (AIC_BASE + 0x00FC)	//Interrupt Source Vector Register 1 (1-31)

//Bits
#define SYS (1<<1)	//System-Bit in AIC_IECR

//Opcode für LDR PC,[PC,# -0xf20], die Anweisung, die nach 0x18 geschrieben werden soll
#define OPCODE 0xE51FFF20
//Opcode für LDR PC,PC 0x100
#define SWI_OPCODE 0xE49FF100

//Funktionen
void enableAICInterrupts();

void remap();

void handler();
#endif
